package no.sachmuld.methodcombination.examples.reflection.aopstyle.request;

import no.sachmuld.methodcombination.api.CrosscuttingBehaviour;
import no.sachmuld.methodcombination.api.MethodInvocation;

/**
 *
 */
public class TransactionalBehaviour extends CrosscuttingBehaviour {

    @Override
    public Object around(MethodInvocation<?> methodInvocation) {
        if (methodInvocation.getMethod().getAnnotation(Transactional.class) != null) {
            System.out.println("begin transaction");
            try {
                return methodInvocation.proceed();
            } finally {
                System.out.println("commit transaction");
            }
        } else {
            return methodInvocation.proceed();
        }
    }
}
